package com.acme.bankapp.domain;

import java.io.Serializable;

import com.acme.bankapp.exceptions.NotEnoughFundsException;

public abstract class AbstractAccount implements Account, Serializable{

	protected int id;
	protected double balance;

	public AbstractAccount(final double amount) {
		this.balance = amount;
	}

	public double getBalance() {
		return balance;
	}
	public long decimalValue() {
		return Math.round(balance);
	}
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(balance);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result + id;
		return result;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AbstractAccount other = (AbstractAccount) obj;
		if (Double.doubleToLongBits(balance) != Double
				.doubleToLongBits(other.balance))
			return false;
		if (id != other.id)
			return false;
		return true;
	}
	

	public String toString() {
		return "Account [balance=" + balance + "]";
	}

	public abstract void deposit(final double amount) throws NotEnoughFundsException;

	public abstract void withdraw(final double amount) throws NotEnoughFundsException;
	public abstract double maximumAmountToWithdraw();

}
